# include <bits/stdc++.h>
# define MAXN 100023
using namespace std;

char buf[1 << 18], *fs, *ft;
char ops[1 << 18], *opt = ops, *const opt_end = ops + (1 << 18);
 
inline char getc() { 
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
 
inline int gn() { 
    int k = 0, f = 1;
    char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}
 
inline void out() { 
    fwrite(ops, 1, opt - ops, stdout);
    opt = ops;
}
 
inline void out(int x, char c) { 
    static char *p = new char[21]();
    *(++p) = c;
    do { 
        *(++p) = x % 10 | 0x30;
        x /= 10;
    } while(x);
    while(*p) { 
        *(opt++) = *(p--);
        if(opt == opt_end) out();
    }
}

inline void out(char c) { 
    *(opt++) = c;
    if(opt == opt_end) out();
}

int mx[MAXN << 2], M;

inline void build(int n) {
    memset(mx, 127, sizeof(mx));
    for(M = 1; M + 1 <= n; M <<= 1);
    for(int i = M + 1; i <= M + n; i++) {
        mx[i] = gn();
    }
    for(int i = M; i >= 1; i--) {
        mx[i] = min(mx[i << 1], mx[i << 1 | 1]);
    }
}

inline int que(int l, int r) {
    int ans = 0x7fffffff;
    for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
        if(~l & 1) ans = min(ans, mx[l + 1]);
        if(r & 1) ans = min(ans, mx[r - 1]);
    }
    return ans;
}

int main() {
    // freopen("climb.in","r",stdin);
    // freopen("climb.out","w",stdout);
    int n = gn();
    int m = gn();
    build(n);
    for(int i = 1; i <= m; i++) {
        int l = gn(), r = gn();
        out(que(l, r), ' ');
    }
    out(' ');
    out();
}
